﻿var _oCalPopUp;
var _oCalInput;

function showItem(oImg)
{	
	if (oImg.readOnly == true || oImg.disabled == true)
	{
		return false;
	}
	var oInput = oImg.parentElement.previousSibling.firstChild;
	
	_oCalInput = oInput;
	_oCalPopUp = window.createPopup();
	
	var sAmountField = document.all["txtAmountFiled"].value;
	var arrAmountFieldList = sAmountField.split(";");
	var iCount = 0;
    for (var i=0 ; i <= arrAmountFieldList.length - 2; i++)
    {
        var arrAmountField = arrAmountFieldList[i].split(",");
        if (iCount < arrAmountField[0].length)
        {
            iCount = arrAmountField[0].length;
        }
    }
    
	_oCalPopUp.document.body.innerHTML = DrawSelectItem(oInput);

	var iCalWidth = 100 ;
	if (11*iCount > 100)
	{
	    iCalWidth = 11*iCount;
	}

	var iCalHeight = 17*(arrAmountFieldList.length);
	var iLeft  = oImg.offsetWidth - iCalWidth;
	var iTop = 18;
		
	if (typeof (showPopup) == "function")
    {
        showPopup(_oCalPopUp, iLeft, iTop, iCalWidth, iCalHeight, event.srcElement);
    }
    else
    {
        _oCalPopUp.show(iLeft, iTop, iCalWidth, iCalHeight, event.srcElement);
    }
}

//画备选项
function DrawSelectItem(oSelect)
{
    var sAmountField = document.all["txtAmountFiled"].value;
    var sSelectAmount = oSelect.value;
    var arrAmountFieldList = sAmountField.split(";");
    
	var sSelectStyle = "font-size:9pt;font-family:宋体,Tahoma, Verdana, Arial;color:#FFFFFF;background-color:#0A246A;width:100%;cursor:default";
	var sCommonStyle = "font-size:9pt;font-family:宋体,Tahoma, Verdana, Arial;color:#000000;background-color:#FFFFFF;width:100%;cursor:default";
	var sHtml = "<table id='tabMenu' table-layout :fixed ; cellpadding='0' cellspacing='0'style='border:1px solid #000000;width:100% ;>";
	if (sSelectAmount == "")
	{
	    sHtml += "<tr height='15'><td AmountText='' AmountValue='' onmouseover='parent.moveOver(this)' onmouseout='parent.moveOut(this)' onClick='parent.ClickAmount(this)' style='"+ sSelectStyle +"'>&nbsp;</td></tr>";
	}
	else
	{
	    sHtml += "<tr height='15'><td AmountText='' AmountValue='' onmouseover='parent.moveOver(this)' onmouseout='parent.moveOut(this)' onClick='parent.ClickAmount(this)' style='"+ sCommonStyle +"'>&nbsp;</td></tr>";
	}
	
	for (var i=0 ; i <= arrAmountFieldList.length - 2; i++)
    {
        var arrAmountField = arrAmountFieldList[i].split(",");
        if (sSelectAmount == arrAmountField[0])
        {
             sHtml += "<tr height='15'><td AmountText='"+ arrAmountField[0] +"' AmountValue='" + arrAmountField[1] + "' onmouseover='parent.moveOver(this)' onmouseout='parent.moveOut(this)' onClick='parent.ClickAmount(this)' style='"+ sSelectStyle +"'>"+ arrAmountField[0] +"</td></tr>";
        }
        else
        {
            sHtml += "<tr height='15'><td AmountText='"+ arrAmountField[0] +"' AmountValue='" + arrAmountField[1] + "' onmouseover='parent.moveOver(this)' onmouseout='parent.moveOut(this)' onClick='parent.ClickAmount(this)' style='"+ sCommonStyle +"'>"+ arrAmountField[0] +"</td></tr>";
        }
    }
	sHtml += "</table>";
	
	return sHtml;
}
function ClickAmount(obj)
{
    _oCalInput.value = obj.AmountText;
    _oCalInput.title = obj.AmountText;
    _oCalInput.AmountValue = obj.AmountValue;    
	_oCalInput.fireEvent("onchange");
	_oCalPopUp.hide();
}
function moveOver(obj)
{
    var tabMenu = obj.parentElement.parentElement.parentElement;
    for (var i=0 ; i< tabMenu.rows.length; i++)
    {
        if (tabMenu.rows[i].cells[0].AmountValue == obj.AmountValue)
        {
            tabMenu.rows[i].cells[0].style.backgroundColor = "#0A246A";
            tabMenu.rows[i].cells[0].style.color = "#FFFFFF";
        }
        else
        {
            tabMenu.rows[i].cells[0].style.backgroundColor = "#FFFFFF";
            tabMenu.rows[i].cells[0].style.color = "#000000";
        }
    }
    
}
function moveOut(obj)
{
    obj.style.backgroundColor = "#FFFFFF";
    obj.style.color = "#000000";
}



function loadOption(objSelect)
{
    var sAmountField = document.all["txtAmountFiled"].value;
    var sSelectAmount = objSelect.value;
    var arrAmountFieldList = sAmountField.split(";");
    var len = objSelect.options.length;
    if (len <= 1)
    {
	    for(var i=len-1;i>=0;i--)
	    {
		    objSelect.remove(i);
	    }
	    var oItem ;
	    oItem = document.createElement('option');
        oItem.text = "";
        oItem.value = "";
        objSelect.add(oItem); 
        for (var i=0 ; i <= arrAmountFieldList.length - 2; i++)
        {
            var arrAmountField = arrAmountFieldList[i].split(",");
            
            oItem = document.createElement('option');
            oItem.text = arrAmountField[0];
            oItem.value = arrAmountField[1];
            
            objSelect.add(oItem);
        }
        objSelect.value =sSelectAmount;
    }
}
//修改借方金额和贷方金额
function changeAmount(type,obj)
{
    if(obj)
    {
        var oTr ;
        oTr = obj.parentElement.parentElement.parentElement.parentElement.parentElement.parentElement;
        if(type == "JfAmount")
        {
            oTr.YDDirection = "借方";
            oTr.AmountFiled = obj.AmountValue;
            oTr.AmountFiledCN = obj.value;
            var dfObject = obj.parentElement.parentElement.parentElement.parentElement.parentElement.nextSibling.firstChild.rows[0].cells[0].firstChild;
            dfObject.value = "";
            dfObject.AmountValue = "";
            //obj.parentElement.nextSibling.firstChild.value = "";
        }
        else
        {
            oTr.YDDirection = "贷方";
            oTr.AmountFiled = obj.AmountValue;
            oTr.AmountFiledCN = obj.value;
            var jfObject = obj.parentElement.parentElement.parentElement.parentElement.parentElement.previousSibling.firstChild.rows[0].cells[0].firstChild;
            jfObject.value = "";
            jfObject.AmountValue = "";
            //obj.parentElement.previousSibling.firstChild.value = "";
        }
        if(oTr.EditStatus == "0")
        {
            oTr.EditStatus = "2";
        }
        document.all["txtIsChange"].value = "1";
    }
}

//选择适用范围
function SelectUsedScope()
{
    var strPath = "";
    var strParamList = "";
    if(document.all["txtApplication"].value == "0101")
    {
        strPath="/PubProject/Cwjk/Cwjk_SelectFeeItem.aspx";
        strParamList = "CwztGUID=" + document.all["txtCwztGUID"].value + "&ParentCode=" + document.all["txtParentCode"].value + "&IsUsedScopeRepeat=" + document.all["txtIsUsedScopeRepeat"].value;
        strParamList += "&SelectUsedScope=" + escape(document.all["txtUsedScope"].value) + "&OperTypeGUID="+ document.all["__OperTypeGUID"].value;
    }
    else
    {
        strPath="/PubProject/Cwjk/Cwjk_SelectFundParam.aspx";
        strParamList = "CwztGUID=" + document.all["txtCwztGUID"].value + "&ParentCode=" + document.all["txtParentCode"].value + "&IsUsedScopeRepeat=" + document.all["txtIsUsedScopeRepeat"].value 
        strParamList += "&SelectUsedScope=" + escape(document.all["txtUsedScope"].value) + "&OperTypeGUID="+ document.all["__OperTypeGUID"].value;
    }
    //var oArgs;
    //oArgs.SelectUsedScope = document.all["txtUsedScope"].value;
    var arrRtn = openMyDlg("选择适用范围", strPath, strParamList, "", 320, 480);
    if(arrRtn != undefined)
    {
        if (document.all["txtUsedScope"].value != arrRtn)
        {
            document.all["txtUsedScope"].value = arrRtn;
            var sFile = "/PubProject/CWJK/Cwjk_XMLHTTP.aspx?Application="+ document.all["txtApplication"].value ;
            var sReturns = openCwjkXmlHTTP(sFile,"ConvertToDataFilter",arrRtn);
            if (sReturns != undefined)
            {
                if(document.all["txtParentOperType"].value != "转账业务")
                {
                    document.all["txtDataFilter"].value = document.all["txtParentDataFilter"].value + sReturns;
                }
                else
                {//转账业务修改适用范围时，需要更新凭证分录中的SQL条件
                    var sSecondDataFilter,sKmSqlFilter;
                    var arrPzTable = document.getElementsByTagName("table");
                    for(var i=0; i <= arrPzTable.length -1 ; i++)
                    {
                        if (arrPzTable[i].name != "tabPz")
                        {
                            continue;
                        }
                        for (var j=1; j <= arrPzTable[i].rows.length-1 ; j++)
                        {
                            sKmSqlFilter = arrPzTable[i].rows[j].KmSqlFilterRule;
                            var arrKmsql = sKmSqlFilter.split("(((((");
                            if(arrKmsql.length != 2) continue;
                            sSecondDataFilter = sReturns.replace("AND","");
                            if(arrPzTable[i].rows[j].cells[0].innerText == "1")
                            {                                
                                sSecondDataFilter = sSecondDataFilter.replace(/ItemName/g,"OldItemName");
                                sKmSqlFilter = arrKmsql[0] + "(((((" + sSecondDataFilter + ")))))";
                                arrPzTable[i].rows[j].KmSqlFilterRule = sKmSqlFilter;
                            }
                            else if (arrPzTable[i].rows[j].cells[0].innerText == "2")
                            {
                                sKmSqlFilter = arrKmsql[0] + "(((((" + sSecondDataFilter + ")))))";
                                arrPzTable[i].rows[j].KmSqlFilterRule = sKmSqlFilter;
                            }
                            arrPzTable[i].rows[j].EditStatus = "2";
                        }
                    }
                }
                document.all["txtIsChange"].value = "1";
            }
        }
        
    }
}
function AddEntry(obj)
{
    if (obj)
    {
        InsertRow(obj);
        document.all["txtIsChange"].value = "1";
    }
}
//****************** 新增、删除行 *****************//
//新增行
// 参数：sValue		- 插入行的信息
// 如果插入的是基表的记录，则oid为基表的guid。
// 如果从其他表中引入记录，或者非引入方式插入纪录，则oid为新产生的的guid。
function InsertRow(obj)
{
    var objTable = document.all["tabPz"+obj];
    var sApplication = document.all["txtApplication"].value;
	var trHTML = objTable.rows[objTable.rows.length-1].outerHTML;
	var sInnerHtml;
	var objAddRow = objTable.insertRow(objTable.rows.length);
	var objPzTr = document.all["tr_"+obj];

	//设置行属性
	with (objAddRow)
	{
		setAttribute("PzEntryRuleGUID", GetGUIDFromXMLHTTP());		// 赋予guid，因为oid无值时无法选择行。
		setAttribute("EditStatus", "1");
		setAttribute("GroupName",objPzTr.GroupName);
		setAttribute("PzName",objPzTr.PzName);
		setAttribute("PzOrderCode",objPzTr.PzOrderCode);
		setAttribute("KmSqlFilterRule",objPzTr.KmSqlFilterRule);
		setAttribute("Zy","");
		setAttribute("ZySql","");
		setAttribute("ZyText","");
		setAttribute("KjkmGUID","");
		setAttribute("YDDirection","");
		setAttribute("AmountFiled","");
		setAttribute("AmountFiledCN","");
		setAttribute("IsInversion","1");
		setAttribute("height", "24");
		setAttribute("KjkmFullName","");//aobo add by 20100726  增加一行时，会计科目名称为空 否则为undefined
	}
	var sNum = objTable.rows.length-1;
	//序号
	objAddCell = objAddRow.insertCell(0);
	objAddCell.align = "center";
	objAddCell.insertAdjacentHTML("BeforeEnd",sNum);
	objAddCell.className="tdClass";
	
	//摘要
	objAddCell = objAddRow.insertCell(1);
	sDtm = '<table cellpadding="0" cellspacing="0" width="100%" style="TABLE-LAYOUT:fixed">';
	sDtm += '<col></col><col width="25" align="right"></col><tr><td><input type="text" value="" readonly="true" style="background-color:transparent;border-color:#cccccc"></input></td>';
	sDtm += '<td align="right"><img style="cursor:hand" src="/_imgs/btn_off_lookup.gif" onclick="SelectZy(this)"></img></td></tr></table>';
	objAddCell.insertAdjacentHTML("BeforeEnd",sDtm);
	objAddCell.className = "tdClass";
	
	//会计科目
	objAddCell = objAddRow.insertCell(2);
	sDtm = '<table cellpadding="0" cellspacing="0" width="100%" style="TABLE-LAYOUT:fixed">';
	sDtm += '<col></col><col width="25" align="right"></col><tr><td><input type="text" value="" readonly="true" style="background-color:transparent;border-color:#cccccc"></input></td>';
	sDtm += '<td align="right"><img style="cursor:hand" src="/_imgs/btn_off_lookup.gif" onclick="SelectKjkm(this)"></img></td></tr></table>';
	objAddCell.insertAdjacentHTML("BeforeEnd",sDtm);
	objAddCell.className = "tdClass";
	
	//辅助核算
	objAddCell = objAddRow.insertCell(3);	
	sDtm = '<input type="text" width="100%" value="" readonly="true" style="background-color:transparent;border-color:#cccccc"></input>';			
	objAddCell.insertAdjacentHTML("BeforeEnd",sDtm);
	objAddCell.className = "tdClass";

	//借方金额
	objAddCell = objAddRow.insertCell(4);
	sDtm = '<table cellpadding="0" cellspacing="0" width="100%" style="TABLE-LAYOUT:fixed">'
	sDtm += '<col></col><col width="17" align="right"></col><tr><td><input type="text" readonly="true" style="background-color:transparent;border-color:#cccccc" onchange="changeAmount(\'JfAmount\',this)" value="" title="" AmountValue=""></input></td>';
	sDtm += '<td align="right"><img style="cursor:hand" src="/_imgs/selectOff.gif" onclick="showItem(this)"></img></td></tr></table>';
	objAddCell.insertAdjacentHTML("BeforeEnd", sDtm);
	
	objAddCell.className = "tdClass";
	
	//贷方金额
	objAddCell = objAddRow.insertCell(5);
	sDtm = '<table cellpadding="0" cellspacing="0" width="100%" style="TABLE-LAYOUT:fixed">'
	sDtm += '<col></col><col width="17" align="right"></col><tr><td><input type="text" readonly="true" style="background-color:transparent;border-color:#cccccc" onchange="changeAmount(\'DfAmount\',this)" value="" title="" AmountValue=""></input></td>';
	sDtm += '<td align="right"><img style="cursor:hand" src="/_imgs/selectOff.gif" onclick="showItem(this)"></img></td></tr></table>';
	objAddCell.insertAdjacentHTML("BeforeEnd", sDtm);

	objAddCell.className = "tdClass";
	
	//金额规则
	if (sApplication == "0101")
	{
	    objAddCell = objAddRow.insertCell(6);
	    sDtm = '<select name="AmountRule" style="WIDTH:100%;" ><option value="1" selected> X 1</option><option value="-1" > X -1</option></select>';
	    objAddCell.insertAdjacentHTML("BeforeEnd", sDtm);
	    objAddCell.className = "tdClass";
	    
        objAddCell = objAddRow.insertCell(7);
        sDtm = '<img src="/images/Delete_16_blue.gif" onclick="DeleteEntry(this)" style="cursor:hand;"></img>';
        objAddCell.insertAdjacentHTML("BeforeEnd", sDtm);
        objAddCell.className = "tdClass";
	     
	}
	else
	{	    
        objAddCell = objAddRow.insertCell(6);
        sDtm = '<img src="/images/Delete_16_blue.gif" onclick="DeleteEntry(this)" style="cursor:hand;"></img>';
        objAddCell.insertAdjacentHTML("BeforeEnd", sDtm);
        objAddCell.className = "tdClass";
	}	
	return objAddRow;
}

function DeleteEntry(obj)
{
   var oTr = obj.parentElement.parentElement;
   var sPzOrderCode = oTr.PzOrderCode;
   var objTable = document.all["tabPz"+sPzOrderCode];
   if (oTr.EditStatus != "1")
   {
        if (document.all["txtDeletePzEntryGUIDList"].value == "")
        {
            document.all["txtDeletePzEntryGUIDList"].value = oTr.PzEntryRuleGUID ;
        }
        else
        {
            document.all["txtDeletePzEntryGUIDList"].value += "," +  oTr.PzEntryRuleGUID ;
        }
   }
   oTr.removeNode(true);
   
   //删除完成后
    if (objTable.rows.length>1)
    {
	    // 需要对行的序号重整
	    for (var i=1; i<objTable.rows.length; i++)
	    {
	        if (objTable.rows[i].innerText != i && objTable.rows[i].EditStatus != "1")
	        {
	            objTable.rows[i].EditStatus = "2";
	        }
		    objTable.rows[i].cells[0].innerHTML = i;
		    
	    }
    }
    document.all["txtIsChange"].value = "1";
}
//
function SelectZy(obj)
{
    var oTr;
    oTr = obj.parentElement.parentElement.parentElement.parentElement.parentElement.parentElement;
    var sZy = oTr.Zy;
    var sOperTypeGUID = document.all["__OperTypeGUID"].value;
    var sPath = "/PubProject/Cwjk/Cwjk_PzRuleSet_SelectZy.aspx";
    var sParam = "OperTypeGUID=" + sOperTypeGUID ;
    var oArgs = new Object();
    oArgs.Zy = sZy;
    
    var arrRtn = openMyDlg("编辑摘要", sPath, sParam, oArgs, 640, 430);
    if (arrRtn)
    {
        oTr.Zy =arrRtn.Zy;
        oTr.ZySql = arrRtn.ZySql;
        oTr.ZyText = arrRtn.ZyText;
        if(oTr.EditStatus == "0")
        {
            oTr.EditStatus = "2";
        }
        obj.parentElement.previousSibling.firstChild.value = arrRtn.ZyText;
        document.all["txtIsChange"].value = "1";
    }
}
function SelectKjkm(obj)
{
    var oTr;
    oTr = obj.parentElement.parentElement.parentElement.parentElement.parentElement.parentElement;
    var sKjkmGUID = oTr.KjkmGUID;
    var sCwztGUID = document.all["txtCwztGUID"].value;
    var sPath = "/PubProject/Cwjk/Cwjk_PzRuleSet_SelectKjkm.aspx";
    var sParam = "CwztGUID=" + sCwztGUID + "&KjkmGUID=" + sKjkmGUID ;
    
    var arrRtn = openMyDlg("选择会计科目", sPath, sParam, "", 430, 600);
    if (arrRtn)
    {
        oTr.KjkmGUID =arrRtn.KjkmGUID;
        oTr.KjkmFullName = arrRtn.KjkmFullName;
        obj.parentElement.previousSibling.firstChild.value = arrRtn.KjkmFullName;
        if(oTr.EditStatus == "0")
        {
            oTr.EditStatus = "2";
        }
        obj.parentElement.parentElement.parentElement.parentElement.parentElement.nextSibling.firstChild.value = arrRtn.HsxmObjectText;
        document.all["txtIsChange"].value = "1";
    }
}
function SavePzEntryRule()
{
    //校验业务场景、适用范围和凭证字
    if(!CheckPzEntryRule())
    {
        return false;
    }
    var arrTabPz = document.getElementsByTagName("table");
	var i,j;
	var tabPz;
	var sCwztGUID,sOperTypeGUID;
	sCwztGUID = document.all["txtCwztGUID"].value;
	sOperTypeGUID = document.all["__OperTypeGUID"].value;
	//校验及收集凭证分录数据
    var xmlDoc = new ActiveXObject("Microsoft.XMLDOM");
	xmlDoc.loadXML('<PzEntryRules CwztGUID="'+ sCwztGUID +'" OperTypeGUID="'+ sOperTypeGUID +'" OperType="'+ document.all["txtOperType"].value +'" UsedScope="'+ document.all["txtUsedScope"].value + '" DelPzEntry="'+ document.all["txtDeletePzEntryGUIDList"].value +'" DataFilter="'+ document.all["txtDataFilter"].value +'"></PzEntryRules>');
	if (arrTabPz.length > 0)
	{
	    for(i= 0 ; i <= arrTabPz.length -1 ; i++)
	    {
	        tabPz = arrTabPz[i];
	        if (tabPz.name != "tabPz")
	        {
	            continue ;
	        }
	        var trPzz = tabPz.parentElement.parentElement.previousSibling.cells[1].firstChild.rows[1]
	        var sPzName = trPzz.PzName ;
	        var sGroupName = trPzz.GroupName;
	        var sPzz = trPzz.cells[2].firstChild.value;
	        if(tabPz.rows.length < 3)
	        {
	            if(sPzName == "")
	            {
	                alert("凭证分录少于两条！");
	            }
	            else
	            {
	                alert(sPzName + "的凭证分录少于两条！");
	            }
	            return false;
	        }
	        var bIsHasZy = false;
	        for (j=1; j <= tabPz.rows.length -1; j++ )
	        {
	            sPzName = tabPz.rows[j].PzName;
	            sGroupName = tabPz.rows[j].GroupName;
	            //判断是否有摘要
	            if(tabPz.rows[j].ZyText != "")
	            {
	                bIsHasZy = true;
	            }	           
	            //aobo edit of BUG by 20100726	当新增分录且未选择会计科目场景时会计科目名称的值为：undefined  新增时已经增加默认值了，但此处还是增加判断         
	            if(tabPz.rows[j].KjkmFullName == "" || tabPz.rows[j].KjkmFullName == undefined) 
	            {
	                if(sPzName == "")
	                {
	                    alert("分录的“会计科目”不允许为空！");
	                }
	                else
	                {
	                    alert("“"+ sPzName + "”的“会计科目”不允许为空！");
	                }	                
	                return false;
	            }
	            if(tabPz.rows[j].AmountFiled == "")
	            {
	                if (sPzName == "")
	                {
	                    alert("同一分录中的“借方金额”和“贷方金额”不允许同时为空！");
	                }
	                else
	                {
	                    alert("“" + sPzName + "”的同一分录中的“借方金额”和“贷方金额”不允许同时为空！");
	                }
	                return false;
	            }
	            //收集凭证分录数据
	            var sEditStatus = tabPz.rows[j].EditStatus;
	            if (sEditStatus == "1" || sEditStatus == "2")
	            {
	                var pzEntryEl = xmlDoc.createElement("PZ");
	                pzEntryEl.setAttribute("EditStatus",sEditStatus);
	                pzEntryEl.setAttribute("PzEntryRuleGUID",tabPz.rows[j].PzEntryRuleGUID);
	                pzEntryEl.setAttribute("Zy",tabPz.rows[j].Zy);
	                pzEntryEl.setAttribute("ZySql",tabPz.rows[j].ZySql);
	                pzEntryEl.setAttribute("ZyText",tabPz.rows[j].ZyText);
	                pzEntryEl.setAttribute("AmountFiled",tabPz.rows[j].AmountFiled);
	                pzEntryEl.setAttribute("AmountFiledCN",tabPz.rows[j].AmountFiledCN);
	                pzEntryEl.setAttribute("YDDirection",tabPz.rows[j].YDDirection);
	                pzEntryEl.setAttribute("KjkmGUID",tabPz.rows[j].KjkmGUID);
	                pzEntryEl.setAttribute("KmSqlFilterRule",tabPz.rows[j].KmSqlFilterRule);
	                pzEntryEl.setAttribute("IsInversion",tabPz.rows[j].IsInversion);
	                pzEntryEl.setAttribute("EntryNum",tabPz.rows[j].cells[0].innerText);
	                pzEntryEl.setAttribute("Pzz",sPzz);
	                pzEntryEl.setAttribute("PzName",tabPz.rows[j].PzName);
	                pzEntryEl.setAttribute("GroupName",tabPz.rows[j].GroupName);
    	            pzEntryEl.setAttribute("IsDisable","0");
    	            pzEntryEl.setAttribute("PzOrderCode",tabPz.rows[j].PzOrderCode);
	                xmlDoc.documentElement.appendChild(pzEntryEl);
	            }
	        }
	        if(!bIsHasZy)
	        {
	            if(sGroupName == "")
	            {
	                if(sPzName == "")
	                {
	                    alert("凭证所有分录中的“摘要”至少需要有一个不为空！");
	                }
	                else
	                {
	                    alert("“" + sPzName + "”的分录中的“摘要”至少需要有一个不为空！");
	                }
	            }
	            else
	            {
	                alert("“"+sGroupName + "”的“" + sPzName + "”的分录中的“摘要”至少需要有一个不为空！");
	            }
	            return false;
	        }
	    }
	    //保存凭证分录规则
	    var sFile = "/PubProject/CWJK/Cwjk_XMLHTTP.aspx?CwztGUID="+ sCwztGUID ;
        var sReturns = openCwjkXmlHTTP(sFile,"SavePzEntryRule",xmlDoc.xml);
        if (sReturns != undefined)
        {
            var arrRtn = sReturns.split("|")
            if(arrRtn.length == 2)
            {
                if(arrRtn[0] == "YES")
                {
                    window.parent.document.all["lbl_ErrorPzNum"].innerText = arrRtn[1];
                    document.all["txtIsPrompt"].value = "0";                    
                    //执行主界面刷新
		            try
		            {
			            parent.opener.window.RefreshWindow();
		            }
		            catch(e)
		            {}
                    window.parent.refleshGrid(document.all["txtHierarchyCode"].value);
                    return true;
                }
                else
                {
                    alert("保存凭证分录规则时出错，请联系管理员！");
                    return false;
                }
            }
            else
            {
                alert("保存凭证分录规则时出错，请联系管理员！");
                return false;
            }
        }
        else
        {
            alert("保存凭证分录规则时出错，请联系管理员！");
            return false;
        }
	}
	else
	{
	    alert("当前场景没有可保存的凭证分录规则！");
	    return false;
	}
}
//校验业务场景、适用范围和凭证字
function CheckPzEntryRule()
{
    if (document.all["txtOperType"].value == "")
    {
        alert("“业务场景”不允许为空！");
        document.all["txtOperType"].focus();
        return false;
    }
    if(document.all["txtIsShowUsedScope"].value == "True")
    {
        if (document.all["txtUsedScope"].value == "")
        {
            alert("“适用范围”不允许为空！");
            document.all["txtUsedScope"].focus();
            return false;
        }
    }
    //校验凭证字
    var arrPzz = document.getElementsByName("txtPzz");
    for (var i =0 ; i <= arrPzz.length -1 ; i++)
    {
        if(arrPzz[i].value == "")
        {
            var sPzName = arrPzz[i].parentElement.parentElement.PzName;            
            if (sPzName == "")
            {
                alert("“凭证字”不允许为空！");
            }
            else
            {
                alert("“"+ sPzName +"”的“凭证字”不允许为空！");
            }
            arrPzz[i].focus();
            return false;
        }
    }
    //校验业务场景是否重名
    var sCwztGUID = document.all["txtCwztGUID"].value;
    var sParentCode = document.all["txtParentCode"].value;
    var sOperType = document.all["txtOperType"].value;
    var sHierarchyCode = document.all["txtHierarchyCode"].value;
    var sApplication = document.all["txtApplication"].value;
    var sFile = "/PubProject/CWJK/Cwjk_XMLHTTP.aspx";
    sFile += "?CwztGUID=" + sCwztGUID + "&ParentCode=" + sParentCode + "&OperType=" + escape(sOperType) + "&HierarchyCode=" + sHierarchyCode ;
    
    var sReturns = openCwjkXmlHTTP(sFile,"CheckOperTypeNameRepeat",document.all["txtUsedScope"].value);
    if (sReturns != undefined)
    {
        if(sReturns != "False")
        {
            alert("同一业务分类下的业务场景名称不允许相同！");
            return false;
        }
    }
    else
    {
        alert("校验业务场景名称时出错，请联系管理员！");
        return false;
    }
    //校验适用范围是否重复
    if (document.all["txtIsUsedScopeRepeat"].value == "False" && document.all["txtIsShowUsedScope"].value == "True")
    {
        sFile = "/PubProject/CWJK/Cwjk_XMLHTTP.aspx";
        sFile += "?CwztGUID=" + sCwztGUID + "&Application=" + sApplication + "&HierarchyCode=" + sHierarchyCode ;
        
        var sReturns = openCwjkXmlHTTP(sFile,"CheckUsedScopeRepeat",document.all["txtUsedScope"].value);
        if (sReturns != undefined)
        {
            var arrRtn = sReturns.split("|")
            if(arrRtn.length == 2)
            {
                if(arrRtn[0] == "NO")
                {
                    alert("适用范围与当前业务分类下的“"+ arrRtn[1] +"”的适用范围有重复！");
                    return false;
                }
            }
            else
            {
                alert("校验适用范围重复时出错，请联系管理员！");
                return false;
            }
            
        }
        else
        {
            alert("校验适用范围重复时出错，请联系管理员！");
            return false;
        }
    }
    return true;
}


//借贷规则
function changeInversion(obj)
{
    if(obj)
    {
        obj.parentElement.parentElement.IsInversion = obj.value;
        if(obj.parentElement.parentElement.EditStatus == "0")
        {
            obj.parentElement.parentElement.EditStatus = "2";
        }
        document.all["txtIsChange"].value = "1";
    }
}

function changeEditStatus()
{
    var arrTabPz = document.getElementsByName("tabPz");
    for(var i= 0 ; i <= arrTabPz.length -1 ; i++)
	{
	    var tabPz = arrTabPz[i];
	    for (var j=1; j <= tabPz.rows.length -1; j++ )
        {
            tabPz.rows[j].EditStatus = "0";
        }
	}
	return true;
}
function changePzz(sPzOrderCode)
{
    var oTable = document.all["tabPz"+sPzOrderCode];
    for(var i= 1; i <= oTable.rows.length -1 ; i++)
    {
        var oTr = oTable.rows[i];
        if(oTr.EditStatus == "0")
        {
            oTr.EditStatus = "2";
        }
    }
    document.all["txtIsChange"].value = "1";
}
function GetGUIDFromXMLHTTP()
{
    var sFile = "/PubProject/CWJK/Cwjk_XMLHTTP.aspx";
    var sReturns = openCwjkXmlHTTP(sFile,"GetNewID","");
    return sReturns;
}
function chgOperType()
{
    document.all["txtIsChange"].value = "1";
}